<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			#div1{
				height: 200px;
				width: 200px;
				background-color: #FF0000;
			}
			
			button{
				height: 100px;
				width: 200px;
			}
		</style>
	</head>
	<body>
		<div id="div1" name="div-test" class="div-class" style="background-color: cadetblue;">我是div</div>
		<div id="div2" name="div-test" class="div-class" style="background-color: cadetblue;">我是div</div>
		<div id="div3" name="div-test" class="div-class" style="background-color: cadetblue;">我是div</div>
		<button onclick="clickMe()">按钮</button>

	</body>
	<script>
		//通过ID获取
		var div2 = document.getElementById("div2");
		var div_tests = document.getElementsByName("div-test");
		console.log(div_tests.length);
		
		var div2 = div_tests[1];
		console.log(div2);
		
		var divs = document.getElementsByTagName("div");
		console.log(divs);
		
		var all_div_class = document.getElementsByClassName("div-class");
		console.log(all_div_class);
		
		var div2 = divs[1];
		
		function clickMe(){
			var div1 = document.getElementById("div1");
			div1.style.backgroundColor = "black";
		}

	</script>
</html>
